const jwt = require('jsonwebtoken');

const key = "fuTkisMQQ2j1ESC0cbaQen1ZWmkMdvLx"
const expir = 120 * 60 * 1000//2hours(token过期的时间)

const ignoreAuth = [
  '/api/user/reg',
  '/api/user/_login',
  '/api/user/admin_login',
  '/api/user/selAlluser',
  '/api/user/regname',
  '/api/menu/selAlldishes',
  '/api/menu/upload',
  '/api/selAllcomment',
  '/api/selAllcomment/username',
  '/api/category',
  '/api/menu/selCategory',
  '/api/order/list',
  '/api/order/list/username'
]

// 校验token(错误会抛出异常)
const verifyToken = function (token) {
  try {
    let tokenKey = jwt.verify(token, key)
    return {
      code: 200,
      msg: '校验成功',
      tokenKey,
    }
  } catch {
    return {
      code: 100,
      msg: '校验失败'
    }
  }
}
module.exports = {
  verifyToken,
  key,
  expir,
  ignoreAuth
};

